<?php
/**
 * beimuaihui System
 * Copyright(c) 2011-2020 beimuaihui.
 * @license    http://www.gnu.org/licenses/gpl.html     This software Under GPL V3 License
 * beimuaihui@gmail.com
 * http://code.google.com/p/beimuaihui/
 * $Id: IndexController.php 228 2011-05-20 03:18:14Z beimuaihui $
 */
require_once 'Zend/Controller/Action.php';
class Microblog_ExportController extends Baogg_Controller_Action_Site
{
	/**
	 * The default action - show the home page
	 */
	public function docAction ()
	{
		$params=$this->getRequest()->getParams();
		
		$filepath="tmp/{$params['module']}/{$params['controller']}/{$params['action']}/";
		$filename=Baogg_File::fixFileName().'.'.$params['action'];
		
		$file_content=@$params['file_content'];
		if(is_array($file_content)){
			$file_content=implode("",$file_content);
		}	
		$file_content=($file_content);
		//echo $file_content;exit;
		$class='Baogg_File_'.ucwords($params['action']);
		$file_url=$class::genFile($filepath,$filename,$file_content);		
		echo $file_url;
		$this->_helper->viewRenderer->setNoRender();
	}
	public function xlsAction()
	{
		$this->docAction();
	}
	public function zipAction()
	{
		$params=$this->getRequest()->getParams();
		$file_content=@$params['file_content'];
		$json_content=Zend_Json::decode($file_content);
		//echo '<pre>';print_r($json_content);exit;		
		$filepath="tmp/{$params['module']}/{$params['controller']}/{$params['action']}/";
		$filename=Baogg_File::fixFileName().'.'.$params['action'];
		$arr_filename=array();
		$arr_url=array();
		foreach((array)$json_content as $k=>$v){
			//$encoding=mb_detect_encoding($v['title']);
			//echo $encoding;
			$v['title']=mb_convert_encoding($v['title'], "gbk");
			$arr_filename[$k]=$filename.'_'.mt_rand().'.html';
			$arr_url[$k]=$v['link'];			

			$localname=Baogg_File::fixFileName($v['title']).'.html';
			$arr_zip_filename[]=array('filename'=>$filepath.$arr_filename[$k],'localname'=>$localname);
		}
		//gen html files
		Baogg_File_Html::genFiles($filepath,$arr_filename,$arr_url);
		
		//gen pdf files
		/* foreach((array)$arr_filename as $k=>$v){
			Baogg_File_Pdf::genFile($filepath, $v.'.pdf', 'file:///'.BAOGG_UPLOAD_DIR.$filepath.$v);
		} */
		
		//gen zip file
		$file_url=Baogg_File_Zip::genFile($filepath, $filename,$arr_zip_filename);
		
		echo $file_url;
		$this->_helper->viewRenderer->setNoRender();
	}
	public function rssAction()
	{
		$feedData = array(
            'title'=>'Channel Title',
            'description'=>'Channel Description here',
            'link'=>'http://www.example.com',
            'charset'=>'utf8',
            'entries'=>array(
                array(
                    'title'=>'Article 1',
                    'description'=>'Article 1 contents goes here',
                    'link'=>'http://www.example.com/article-1',
                    'guid'=>'1A'
                ),
                array(
                    'title'=>'Article 2',
                    'description'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
                    'link'=>'http://www.example.com/article-2',
                    'guid'=>'2A'
                )
            )
        );
        // create our feed object and import the data
        $feed = Zend_Feed::importArray ( $feedData, 'rss' );
 
        // set the Content Type of the document
        header ( 'Content-type: text/xml' );
 
        // echo the contents of the RSS xml document
        echo $feed->send();
        $this->_helper->viewRenderer->setNoRender();
        
	}
}